package org.example.platform.beans.factory.Autoware.io;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

public class UrlResource  implements Resource{

    private final URL url;

    public UrlResource(URL url) {
        this.url = url;
    }

    @Override
    public InputStream getInputStream() throws IOException {
        URLConnection connection = url.openConnection();
        try{
            return connection.getInputStream();
        }catch (Exception e){
            if(connection instanceof HttpURLConnection){
                (( HttpURLConnection)connection).disconnect();
            }
            throw e;
        }
    }
}
